#!/bin/bash
SWAP=/mnt/swapfile

# Check run by root
if [ "$(id -u)" != "0" ]; then
   echo "This script must be run as root" 1>&2
   exit 1
fi

# Create and Enable swap file
dd if=/dev/zero of=$SWAP bs=1M count=512
mkswap $SWAP
swapon $SWAP
echo "$SWAP       none    swap    sw      0       0 " >> /etc/fstab
sysctl vm.swappiness=10
echo "vm.swappiness=10" >> /etc/sysctl.conf
chown root:root $SWAP
chmod 0600 $SWAP


